<template>
    <div>
        <table>
            <tr>
                <td>账号</td>
                <td><input type="text" v-model="data.name"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="data.pwd"></td>
            </tr>
            <tr>
                <td>图片</td>
                <td>
                    <input type="file" @change="Tent">
                    <img :src="'https://localhost:7087'+data.img" alt="" style="width: 60px;height: 60px;">
                </td>
            </tr>
            <tr>
                <td>时间</td>
                <td><input type="date" v-model="data.seatime"></td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="radio" v-model="data.zhun"  value="启用">启用
                    <input type="radio" v-model="data.zhun"  value="禁用">禁用
                </td>
            </tr>
            <tr>
                <td>描述</td>
                <td><input type="text" v-model="data.ment"></td>
            </tr>
            <tr>
                <td><input type="button" value="修改" @click="xin"></td>
                <a href='/ShowView'>返回</a>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref ,onMounted} from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';

const rount=useRoute()
const rountr=useRouter()

onMounted(() => {
    Show()  
})

const Tent=(e:any)=>{
    var f=e.target.files[0];
    var fd=new FormData();
    fd.append('file',f);
    axios.post("https://localhost:7087/api/UpLog",fd).then(res=>{
        data.value.img=res.data;
    })
}

const data=ref({
  "id": 0,
  "name": "",
  "pwd": "",
  "img": "",
  "seatime": "",
  "zhun": "",
  "ment": ""
})

const Show=()=>{
    var vid=rount.query.id;
    axios.get("https://localhost:7087/api/User/Getupt",{params:{id:vid}}).then(res=>{
        data.value=res.data;
    })

}


const xin=()=>{
    axios.post("https://localhost:7087/api/User/Update",data.value).then(res=>{
        if(res.data>0){
            alert('修改成功')
            rountr.push({path:'/ShowView'})
        }
    })
}


</script>

<style scoped>

</style>